package cn.jianyongjie.fallback;

import cn.jianyongjie.domain.User;
import cn.jianyongjie.feignclient.UserFeignClient;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
// Fiegn接口熔断-fallbackFactory方式
@Component
public class UserFallbackFactory implements FallbackFactory<UserFeignClient> {
    @Override
    public UserFeignClient create(Throwable throwable) {
        // 打印异常
        throwable.printStackTrace();

        // 实例化接口
        return new UserFeignClient() {
            @Override
            public User userById(Long id) {
                // 填写返回值
                return new User(id,"fallbackFactory网络异常",404);
            }
        };
    }
}
